package com.stationbuilding;

import android.app.Application;
import android.content.Context;

import com.danikula.videocache.HttpProxyCacheServer;

public class MyApplication extends Application {
    private static Context context;
    private HttpProxyCacheServer proxy;

    @Override
    public void onCreate() {
        //获取Context
        super.onCreate();
        context = getApplicationContext();
    }

    /**
     * 获取全局的上下文
     */
    public static Context getContext() {
        return context;
    }

    public static HttpProxyCacheServer getProxy() {
        MyApplication app = (MyApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this)
                .maxCacheSize(1024 * 1024 * 100)       // 设置缓存最大限制
                .maxCacheFilesCount(20)                 //设置最多缓存多少个文件
                .build();
    }
}
